﻿using System;

namespace syno_exec.csm.cmd
{
    using ExcelConfig;
    using synoexec.synologylib.DataType;
    using SynologyDotNet;
    using SynologyLIB;
    /// <summary>
    /// 版本备份cmd 
    /// </summary>
    public class ActiveBackupCmd
    {
        /// <summary>
        /// 执行任务
        /// </summary>
        public static async Task<bool> StartTask(params int[] taskid)
        {
            using (var client = new SynoClient(new Uri(cgsys.config.Text("群晖地址")), true))
            {
                var syno = new MySyno(client);
                await syno.LoginAsync(cgsys.config.Text("群晖用户名"), cgsys.config.Text("群晖密码"));

                var rlt = await syno.StartActiveBackup(taskid);
                return rlt.Success;
            }
        }

        public static async Task<BackupTaskInfo[]> ReadTasks()
        {
            using (var client = new SynoClient(new Uri(cgsys.config.Text("群晖地址")), true))
            {
                var syno = new MySyno(client);

                await syno.LoginAsync(cgsys.config.Text("群晖用户名"), cgsys.config.Text("群晖密码"));
                var tasks = await syno.ReadActiveBackupTasks();
                if (tasks.Success)
                {
                    return tasks.Data.Tasks;
                }
                return Array.Empty<BackupTaskInfo>();
            }
        }
    }
}
